package com.ak.ty.quartz;

import com.ak.ty.dao.User;
import com.ak.ty.entity.UserMapper;
import com.ak.ty.service.impl.TyServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Slf4j
@PersistJobDataAfterExecution
public class Clock implements Job {

    @Autowired
    UserMapper userMapper;

    @Autowired
    TyServiceImpl service;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<User> users = userMapper.selectList(null);
        for (User user : users) {
            try {
                Thread.sleep(1000);
                service.email("12点啦，该打卡啦---，一次打两次", user.getEmail());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
